﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNH.MyForms;

namespace QLNH.MyLayouts
{
    public partial class LayoutAdmin : LayoutUC
    {
        #region Properties

        private int _selectedIndex = -1;

        #endregion

        #region Constructor

        public LayoutAdmin(MainForm mainForm)
        {
            this.mainForm = mainForm;
            InitializeComponent();
            SwitchForm(FormKey.ADMIN_MAIN_FORM);
        }

        #endregion

        #region Functions

        public override void SwitchForm(FormKey key)
        {
            if (this.curentForm != key)
            {
                switch (key)
                {
                    case FormKey.ADMIN_MAIN_FORM:
                        InstallForm(new AdminMainForm(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_ACCOUNT_MANAGEMENT:
                        InstallForm(new AdminAccountManagement(this));
                        _selectedIndex = lmbt_account.Index;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_ACCOUNT_EDIT:
                        InstallForm(new AdminAccountEdit(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_RESTAURANT_INFO_EDIT:
                        InstallForm(new AdminRestaurantInfoEdit(this));
                        _selectedIndex = lmbt_info.Index;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_MENU_MANAGEMENT:
                        InstallForm(new AdminMenuManagement(this));
                        _selectedIndex = lmbt_menu.Index;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_MENU_EDIT:
                        InstallForm(new AdminMenuEdit(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_CATALOG_MANAGEMENT:
                        InstallForm(new AdminCatalogManagement(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_TABLE_MANAGEMENT:
                        InstallForm(new AdminTableManagement(this));
                        _selectedIndex = this.lmbt_table.Index;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_EVENT_MANAGEMENT:
                        InstallForm(new AdminEventManagement(this));
                        _selectedIndex = this.lmbt_event.Index;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_EVENT_EDIT:
                        InstallForm(new AdminEventEdit(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_STATISTICS:
                        InstallForm(new AdminStatistics(this));
                        _selectedIndex = this.lmbt_statitics.Index;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_SALE_STATISTIC:
                        InstallForm(new AdminSaleStatistic(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_FAVORITE_FOODS_STATISTIC:
                        InstallForm(new AdminFavoriteFoodsStatistic(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    default:
                        break;
                }
            }

            if (key != FormKey.ADMIN_MAIN_FORM)
            {
                this.bt_home.Visible = true;
            }
            else
            {
                this.bt_home.Visible = false;
            }
        }

        public override void SwitchForm(FormKey key, params object[] values)
        {
            if (this.curentForm != key)
            {
                switch (key)
                {
                    case FormKey.ADMIN_MAIN_FORM:
                        InstallForm(new AdminMainForm(this));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_ACCOUNT_MANAGEMENT:
                        InstallForm(new AdminAccountManagement(this));
                        _selectedIndex = lmbt_account.Index;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_ACCOUNT_EDIT:
                        InstallForm(new AdminAccountEdit(this, values));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_MENU_EDIT:
                        InstallForm(new AdminMenuEdit(this, values));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    case FormKey.ADMIN_EVENT_EDIT:
                        InstallForm(new AdminEventEdit(this, values));
                        _selectedIndex = -1;
                        SetSelectedColor();
                        break;
                    default:
                        break;
                }
            }

            if (key != FormKey.ADMIN_MAIN_FORM)
            {
                this.bt_home.Visible = true;
            }
            else
            {
                this.bt_home.Visible = false;
            }
        }
        //resize lai form va hien thi len layout
        public override void InstallForm(FormUC form)
        {
            form.Resize(this.pn_content.Size);
            this.curentForm = form.Formkey;
            this.pn_content.Controls.Clear();
            this.pn_content.Controls.Add(form);
            this.lb_formName.Text = form.FormName;
        }

        //doi mau nut menu trai
        public void SetSelectedColor()
        {
            lmbt_statitics.Pressed = false;
            lmbt_statitics.ChangeBackGroundImage();

            lmbt_menu.Pressed = false;
            lmbt_menu.ChangeBackGroundImage();

            lmbt_event.Pressed = false;
            lmbt_event.ChangeBackGroundImage();

            lmbt_account.Pressed = false;
            lmbt_account.ChangeBackGroundImage();

            lmbt_table.Pressed = false;
            lmbt_table.ChangeBackGroundImage();

            lmbt_info.Pressed = false;
            lmbt_info.ChangeBackGroundImage();

            switch (_selectedIndex)
            {
                case 0:
                    lmbt_statitics.Pressed = true;
                    lmbt_statitics.ChangeBackGroundImage();
                    break;
                case 1:
                    lmbt_menu.Pressed = true;
                    lmbt_menu.ChangeBackGroundImage();
                    break;
                case 2:
                    lmbt_event.Pressed = true;
                    lmbt_event.ChangeBackGroundImage();
                    break;
                case 3:
                    lmbt_account.Pressed = true;
                    lmbt_account.ChangeBackGroundImage();
                    break;
                case 4:
                    lmbt_table.Pressed = true;
                    lmbt_table.ChangeBackGroundImage();
                    break;
                case 5:
                    lmbt_info.Pressed = true;
                    lmbt_info.ChangeBackGroundImage();
                    break;
                default:
                    break;
            }
        }

        //cap nhat thong tin nha hang
        public void UpdateInfo()
        {
            this.mainForm.GetInfo();
        }

        //an thanh menu trai
        private bool IsCollapsed = false;
        private void CollapseLeftPanel()
        {
            if (IsCollapsed)
            {
                //this.bt_collapse.Text = "<";
                this.pn_left.Size = new Size(0, this.Height);
            }
            else
            {
                //this.bt_collapse.Text = ">";
                this.pn_left.Size = new Size(200, this.Height);
            }

            //this.bt_collapse.Location = new Point(this.pn_left.Width - this.bt_collapse.Width - 3, this.panel1.Height / 2 - this.bt_collapse.Height / 2);
            IsCollapsed = !IsCollapsed;
        }
             
        #endregion

        #region Control Events

        private void pn_content_Resize(object sender, EventArgs e)
        {
            if (this.pn_content.Controls.Count > 0)
            {
                ((FormUC)this.pn_content.Controls[0]).Resize(this.pn_content.Size);
            }
        }

        private void pn_split_SplitterMoved(object sender, SplitterEventArgs e)
        {
            //this.bt_collapse.Location = new Point(this.pn_left.Width - this.bt_collapse.Width - 3, this.panel1.Height / 2 - this.bt_collapse.Height / 2);

            if (this.pn_left.Size.Width < 200)
            {
                IsCollapsed = true;
            }
            else
            {
                IsCollapsed = false;
            }

            CollapseLeftPanel();
        }

        private void pn_split_DoubleClick(object sender, EventArgs e)
        {
            CollapseLeftPanel();
        }

        private void bt_home_Click(object sender, EventArgs e)
        {
            SwitchForm(FormKey.ADMIN_MAIN_FORM);
        }

        private void lmbt_statitics_Click(object sender, EventArgs e)
        {
            SwitchForm(FormKey.ADMIN_STATISTICS);
        }

        private void lmbt_menu_Click(object sender, EventArgs e)
        {
            SwitchForm(FormKey.ADMIN_MENU_MANAGEMENT);
        }

        private void lmbt_event_Click(object sender, EventArgs e)
        {
            SwitchForm(FormKey.ADMIN_EVENT_MANAGEMENT);
        }

        private void lmbt_account_Click(object sender, EventArgs e)
        {
            SwitchForm(FormKey.ADMIN_ACCOUNT_MANAGEMENT);
        }

        private void lmbt_table_Click(object sender, EventArgs e)
        {
            SwitchForm(FormKey.ADMIN_TABLE_MANAGEMENT);
        }

        private void lmbt_info_Click(object sender, EventArgs e)
        {
            SwitchForm(FormKey.ADMIN_RESTAURANT_INFO_EDIT);
        }

        #endregion       
    }
}
